<template>
	<view class="tabbar">
		<u-tabbar v-model="currents" :list="list" active-color="#376DFF" height="105" @change='changeVue'></u-tabbar>
		<u-toast ref="uToast" />
		<u-popup v-model="show" mode="center" border-radius="12" :closeable="false" width="660" height="460">
			<view class="dialog-1">
				<view class="name">
					提示
				</view>
				<view class="text">
					请先【创建任务】，再进行扫描
				</view>
				<view class="btn-box">
					<u-button class="btn" type="primary" shape="circle" @click="onsubmit">确认</u-button>
				</view>
			</view>
		</u-popup>
		<!-- 提示框 -->
		<u-modal v-model="tipsshow" :content="content" :show-cancel-button="true" @confirm="tipconfirm"></u-modal>
	</view>
</template>

<script>
	export default {
		props: ['current'],
		data() {
			return {
				tipsshow:false,
				skip:0,
				content:'当前任务尚未保存，真的要退出吗？',
				list: [{
						iconPath: "home",
						selectedIconPath: "home-fill",
						text: '首页',
						customIcon: false,
					},
					{
						iconPath: "plus-circle",
						selectedIconPath: "plus-circle-fill",
						text: '创建项目',
						customIcon: false,
					},
					{
						iconPath: "grid",
						selectedIconPath: "grid-fill",
						text: '扫码',
						customIcon: false,
					},
					{
						iconPath: "calendar",
						selectedIconPath: "calendar-fill",
						text: '历史任务',
						customIcon: false,
					},
					{
						iconPath: "account",
						selectedIconPath: "account-fill",
						text: '我的',
						customIcon: false,
					},
				],
				show: false,
			};
		},
		computed: {
			currents: {
				get() {
					return this.current
				},
				set() {} //添加一个空setter防止报错

				// return this.current;
			},
			userinfo: {
				get() {
					return this.$store.state.userinfo;
				},
				set() {

				}
			},
			home: {
				get() {
					return this.$store.state.home;
				},
				set() {

				}
			}
		},
		methods: {
			changeVue(e) {
				this.skip=e;
				console.log('this.currents',this.currents)
				if (this.currents == e) {
					console.log('不能点击自己哦！')

					return
				}
				if(this.currents==1&&e!= 2){
				   this.tipsshow=true
				   return
				}else{
					
					if (e == 0) {
						uni.navigateTo({
							url: '/pages/index/index'
						})
					}
					if (e == 1) {
						uni.navigateTo({
							url: '/pages/createTask/createTask'
						})
					}
					if (e == 2) {
						// this.scanCode()
						// uni.removeStorageSync('scansnum');
						// uni.removeStorageSync('affirm');
						// uni.removeStorageSync('isCreate');
						var Create = uni.getStorageSync('isCreate')
						if (Create == 1) {
					
							uni.navigateTo({
								url: '/pages/scanningcode/scanningcode'
							})
						} else {
							this.show = true
							// uni.showToast({
							// 	title: '请先创建任务',
							// 	icon: 'none'
							// })
						}
					
					}
					if (e == 3) {
						uni.navigateTo({
							url: '/pages/historicalTasks/historicalTasks'
						})
					}
					if (e == 4) {
						uni.navigateTo({
							url: '/pages/my/my'
						})
					}
				}
				// if (e == 2) {
				// 	if(!this.userinfo){
				// 		this.$refs.uToast.show({
				// 			title: '您还没有登录，快去登录后再来吧！',
				// 			type: 'error'
				// 		})
				// 		setTimeout(()=>{
				// 			uni.navigateTo({
				// 				url:'/pages/login/login'
				// 			})
				// 		},200)
				// 		return
				// 	}
				// 	let url=`${this.home.shop}/#/pages/index/index?token=${this.userinfo.token}`;
				// 	setTimeout(()=>{
				// 		uni.navigateTo({
				// 			url:`/pages/shop/shop?url=${url}`
				// 		})
				// 	},300)
				// 	// setTimeout(() => {
				// 	//    window.location.href=url;
				// 	// }, 300);

				// }
				// if (e == 3) {
				// 	if(!this.userinfo){
				// 		this.$refs.uToast.show({
				// 			title: '您还没有登录，快去登录后再来吧！',
				// 			type: 'error'
				// 		})
				// 		setTimeout(()=>{
				// 			uni.navigateTo({
				// 				url:'/pages/login/login'
				// 			})
				// 		},200)
				// 		return
				// 	}
				// 	uni.navigateTo({
				// 		url: '/pages/user/user'
				// 	})
				// }


			},
			tipconfirm(){
				this.tipsshow=false
				if (this.skip == 0) {
						uni.navigateTo({
							url: '/pages/index/index'
						})
					}
					if (this.skip == 1) {
						uni.navigateTo({
							url: '/pages/createTask/createTask'
						})
					}
					if (this.skip == 2) {
						
						var Create = uni.getStorageSync('isCreate')
						if (Create == 1) {
					
							uni.navigateTo({
								url: '/pages/scanningcode/scanningcode'
							})
						} else {
							this.show = true
							
						}
					
					}
					if (this.skip == 3) {
						uni.navigateTo({
							url: '/pages/historicalTasks/historicalTasks'
						})
					}
					if (this.skip == 4) {
						uni.navigateTo({
							url: '/pages/my/my'
						})
					}
			},
			scanCode() {
				// 允许从相机和相册扫码
				uni.scanCode({
					success: function(res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
					}
				});
			},
			onsubmit(){
				this.show=false;
				uni.navigateTo({
					url: '/pages/createTask/createTask'
				})
			}

		}
	}
</script>

<style lang="scss">
	.dialog-1 {
		padding: 64rpx 32rpx;

		.name {
			font-size: 24px;
			color: #10275A;
			margin-bottom: 64rpx;
		}

		.text {
			font-size: 32rpx;
			color: #181B1F;
			margin-bottom: 64rpx;
		}

		.card-border {
			border: 1px solid #999999;
			margin-bottom: 30rpx;
			padding: 32rpx;
			border-radius: 16rpx;
		}
	}
</style>
